﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZP.Common;
using ZP.DTO.Common;
using ZP.DTO.fz_base_employee;
using ZP.IBLL;

namespace ZCSBZPJ.Controllers
{
    public class FZEmployeeController : BaseController
    {
        //public FZEmployeeController(Ifz_base_employeeService _fz_base_employeeService)
        //{
        //    this._fz_base_employeeService = _fz_base_employeeService;
        //}

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 员工信息-模糊分页查询
        /// </summary>
        /// <returns></returns>
        public JsonResult GetBaseEmployee(fz_base_employeeSearchDTO dto)
        {
            PageModel<fz_base_employeeResultDTO> pageList = new PageModel<fz_base_employeeResultDTO>();
            try
            {
                pageList = _fz_base_employeeService.GetBaseEmployee(dto);
            }
            catch (Exception ex)
            {
                pageList.msg = ex.Message;
            }
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 保存员工-新增/修改
        /// </summary>
        /// <returns></returns>
        public JsonResult SaveBaseEmployee(fz_base_employeeOperateDTO dto)
        {
            ResultData<string> result = new ResultData<string>();
            try
            {
                UserLoginDTO loginUser = (UserLoginDTO)Session[ZPCommon.SESSION_Login];
                dto.updater = loginUser.account;
                result.SubmitResult = _fz_base_employeeService.SaveBaseEmployee(dto);
            }
            catch (Exception e)
            {
                result.SubmitResult = false;
                result.Message = e.Message;
            }

            return Json(result);
        }

        /// <summary>
        /// 删除员工(逻辑删除)
        /// </summary>
        /// <returns></returns>
        public JsonResult DeleteBaseEmployee(List<fz_base_employeeOperateDTO> dto)
        {
            ResultData<string> result = new ResultData<string>();
            try
            {
                UserLoginDTO loginUser = (UserLoginDTO)Session[ZPCommon.SESSION_Login];
                result.SubmitResult = _fz_base_employeeService.DeleteBaseEmployee(dto, loginUser);
            }
            catch (Exception ex)
            {
                result.SubmitResult = false;
                result.Message = ex.Message;
            }
            return Json(result);
        }
    }
}